home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15382 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.2 KB

  1. Path: ix.netcom.com!news
  2. From: jhewett@ix.netcom.com (Jerry Hewett)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: screen->metafile
  5. Date: Fri, 05 Apr 96 01:15:00 GMT
  6. Organization: Netcom
  7. Message-ID: <N.040496.171500.24@ix.netcom.com>
  8. References: <pboysen.828654012@abc.cc.iastate.edu>
  9. NNTP-Posting-Host: tem-ca1-16.ix.netcom.com
  10. X-NETCOM-Date: Thu Apr 04  7:18:35 PM CST 1996
  11. X-Newsreader: Quarterdeck Message Center [2.00]
  12.  
  13. On 4/4/96 1:40PM, in message <pboysen.828654012@abc.cc.iastate.edu>, Pete 
  14. Boysen <pboysen@iastate.edu> wrote:
  15.  
  16. > I would like to copy a rectangular bitmap defined by rect to a metaDC 
  17. > however the BitBlt function always fails. How can I do this? Do I need 
  18. > to use device-independent bitmaps? Below is the code I am currently using
  19. > to do this:
  20.  
  21. I was trying to figure out how to use DIB's myself just a couple of weeks ago, 
  22. and came across this article on one of the MS Developer Network CD's.  Hope 
  23. this at least points you in the right direction! :-)
  24.  
  25. ----<snip>----
  26.  
  27. [excerpted from: _DIBs And Their Use_ by Ron Gery; MSDN Technical Article]
  28.  
  29.   SetDIBitsToDevice
  30.   
  31.   SetDIBitsToDevice allows an application to set a DIB directly to a device 
  32.   surface. Because this function is a holdout from early development, its 
  33.   interface is not as polished as it could be. StretchDIBits is a far more 
  34.   powerful function than SetDIBitsToDevice. StretchDIBits does all that 
  35.   SetDIBitsToDevice does and has a nicer interface. SetDIBitsToDevice is 
  36.   limited in the way it handles metafiles because it does not scale, and 
  37.   banding with the nStartScan and nNumScans parameters is nontrivial at best. 
  38.   StretchDIBits does not allow the banding.
  39.   
  40.   The following code performs the SetDIBitsToDevice functionality on the full 
  41.   bitmap (no banding) using StretchDIBits:
  42.   
  43.   StretchDIBits(hDC, x, y, (WORD)lpInfo->biWidth, 
  44.        (WORD)lpInfo->biHeight, 0, 0, (WORD)lpInfo->biWidth, 
  45.        (WORD)lpInfo->biHeight, lpBits, lpInfo, DIB_RGB_COLORS, 
  46.        SRCCOPY)
  47.   
  48.   Assuming that nStartScan is set to 0 and that nNumScans is set to 
  49.   lpInfo->biHeight (that is, no banding), the function is basically a BitBlt 
  50.   with SRCCOPY as the ROP and with a DIB as the source. SrcX and SrcY are in 
  51.   the DIB's space and are therefore upside down in relation to the DC (Y = 0 
  52.   is at the bottom of the image). 
  53.   
  54.   Dealing with the upside-down DIB is tricky when doing a partial setting. 
  55.   For example, if an application wants to get the bottom third of a DIB that 
  56.   is w by h pixels to the device at (x,y), the call would look something like 
  57.   the following:
  58.   
  59.   SetDIBitsToDevice(hDC, x, y, w, h/3, 0, h/3, 0, 
  60.         (WORD)lpInfo->biHeight, lpBits, lpInfo, DIB_RGB_COLORS);
  61.   
  62.   A device-dependent bitmap would have a SrcY of 2h/3 for the bottom third, 
  63.   but with the upside-down system of the DIB, a SrcY of h/3 points to the 
  64.   proper place relative to Windows coordinates.
  65.  
  66. ----<snip>----
  67.  
  68. There's a lot more good, detailed information in the article itself, but the 
  69. long and short of it is that you apparently need to use something like 
  70. StretchDIBits instead of BitBlt to move a bitmapped region into a metafile.
  71.  
  72. I'm guessing this article is available somewhere on the MS website.  If you 
  73. can't locate it let me know.
  74.  
  75. Jerry H.
  76.  
  77.  
  78.